<template>
  <a-layout-sider
    :class="['sider', isDesktop() ? null : 'shadow', theme, fixSiderbar ? 'ant-fixed-sidemenu' : null]"
    width="200px"
    :collapsible="collapsible"
    v-model="collapsed"
    :trigger="null"
  >
    <logo />

    <div class="quick-box" v-if="!collapsed">
      <a-popover placement="rightTop" :overlayStyle="popoverStyle">
        <template slot="content" style="width: 300px">
          <div class="cleanfix">
            <div class="qItem cleanfix" v-for="item in addQuickList" :key="item.index" @click="quickAdd(item.type)">
              <i :class="item.icon" style="margin-right: 8px" />{{ item.title }}
            </div>
          </div>
        </template>
        <div class="quick">快捷创建 <a-icon class="qicon" style="margin-left: 40px" type="plus" /></div>
      </a-popover>
    </div>

    <div class="quick-box" v-else>
      <a-popover placement="rightTop" :overlayStyle="popoverStyle">
        <template slot="content" style="width: 300px">
          <div class="cleanfix">
            <div class="qItem cleanfix" v-for="item in addQuickList" :key="item.index" @click="quickAdd(item.type)">
              <i :class="item.icon" style="margin-right: 8px" />{{ item.title }}
            </div>
          </div>
        </template>
        <div class="quick" style="padding: 0; text-align: center">
          <a-icon class="qicon" type="plus" />
        </div>
      </a-popover>
    </div>

    <s-menu :collapsed="collapsed" :menu="menus" :theme="theme" @select="onSelect" :mode="mode" :style="smenuStyle">
    </s-menu>
  </a-layout-sider>
</template>

<script>
import ALayoutSider from 'ant-design-vue/es/layout/Sider'
import Logo from '../tools/Logo'
import SMenu from './index'
import { mixin, mixinDevice } from '@/utils/mixin.js'
import { httpAction, getAction } from '@/api/manage'
import { mapGetters } from 'vuex'
export default {
  name: 'SideMenu',
  components: { ALayoutSider, Logo, SMenu },
  mixins: [mixin, mixinDevice],
  props: {
    mode: {
      type: String,
      required: false,
      default: 'inline',
    },
    theme: {
      type: String,
      required: false,
      default: 'dark',
    },
    collapsible: {
      type: Boolean,
      required: false,
      default: false,
    },
    collapsed: {
      type: Boolean,
      required: false,
      default: false,
    },
    menus: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      addQuickList: [
        // { title: '线索', icon: 'wk wk-leads',type: 'leads' },
        { title: '客户', icon: 'wk wk-customer', type: 'customer' },
        //  { title: '联系人', icon: 'wk wk-contract' ,type: 'contract'},
        { title: '商机', icon: 'wk wk-business', type: 'business' },
        //  { title: '合同', icon: 'wk wk-contacts' ,type: 'contacts'},
        //  { title: '回款', icon: 'wk wk-receivables',type: 'receivables' },
        //  { title: '回访', icon: 'wk wk-house',type: 'house' },
      ],
    }
  },
  computed: {
    popoverStyle() {
      return { width: '300px' }
    },
    smenuStyle() {
      let style = { padding: '0' }
      if (this.fixSiderbar) {
        style['height'] = 'calc(100% - 59px)'
        style['overflow'] = 'auto'
        style['overflow-x'] = 'hidden'
      }
      return style
    },
  },
  methods: {
     ...mapGetters(['userInfo']),
    onSelect(obj) {
      this.$emit('menuSelect', obj)
    },
    quickAdd(type) {
      this.$emit('quickAdd', type)
    },
  },
}
</script>
<style lang="less" scoped>
/* update_begin author:sunjianlei date:20190509 for: 修改侧边导航栏滚动条的样式 */
.sider {
  @scrollBarSize: 10px;

  ul.ant-menu {
    padding: 15px !important;

    /* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
    &::-webkit-scrollbar {
      width: @scrollBarSize;
      height: @scrollBarSize;
      background-color: transparent;
      display: none;
    }

    & .-o-scrollbar {
      display: none;
    }

    /* 兼容IE */
    -ms-overflow-style: none;
    -ms-scroll-chaining: chained;
    -ms-content-zooming: zoom;
    -ms-scroll-rails: none;
    -ms-content-zoom-limit-min: 100%;
    -ms-content-zoom-limit-max: 500%;
    -ms-scroll-snap-type: proximity;
    -ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);

    /* 定义滚动条轨道 */
    &::-webkit-scrollbar-track {
      background-color: transparent;
    }

    /* 定义滑块 */
    &::-webkit-scrollbar-thumb {
      border-radius: @scrollBarSize;
      background-color: #eee;
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);

      &:hover {
        background-color: #dddddd;
      }

      &:active {
        background-color: #bbbbbb;
      }
    }
  }

  /** 暗色系滚动条样式 */
  &.dark ul.ant-menu {
    &::-webkit-scrollbar-thumb {
      background-color: #666666;

      &:hover {
        background-color: #808080;
      }

      &:active {
        background-color: #999999;
      }
    }
  }
}

/* update_end author:sunjianlei date:20190509 for: 修改侧边导航栏滚动条的样式 */
</style>

<!-- update_begin author:sunjianlei date:20190530 for: 选中首页的时候不显示背景颜色 -->
<style lang="less">
.ant-menu.ant-menu-root {
  & > .ant-menu-item:first-child {
    background-color: transparent;

    & > a,
    & > a:hover {
      color: rgba(0, 0, 0, 0.65);
    }

    &.ant-menu-item-selected {
      & > a,
      & > a:hover {
        color: @primary-color;
      }
    }
  }

  &.ant-menu-dark > .ant-menu-item:first-child {
    & > a,
    & > a:hover {
      color: rgba(255, 255, 255);
    }

    &.ant-menu-item-selected {
      & > a,
      & > a:hover {
        color: rgba(255, 255, 255, 1);
      }
    }
  }
}
</style>

<!-- 侧边栏样式改变 -->
<style lang="less" scoped>
/deep/ .ant-menu-dark .ant-menu-inline.ant-menu-sub {
  background-color: transparent;
  box-shadow: none;
}
/deep/ .ant-menu.ant-menu-dark .ant-menu-item-selected,
.ant-menu-submenu-popup.ant-menu-dark .ant-menu-item-selected {
  background-color: #e47c20 !important;
}

/deep/ .ant-menu-item-selected {
  border-radius: 5px !important;
}
/deep/ .ant-menu-item {
  color: #fff !important;
  border-radius: 5px !important;
}
/deep/.ant-menu-submenu {
  color: #fff !important;
}
/deep/ .ant-menu-item:hover {
  background-color: #6e6e6e65;
}

.quick-box {
  color: #fff;
  padding: 15px 15px 0 15px;
  background-color: #0b5b31;
  .quick {
    padding-left: 24px;
    height: 40px;
    line-height: 40px;
    border-radius: 5px;
    background-color: #168a40;
    cursor: pointer;
  }
}
.quick:hover {
  background-color: #e47c20;
  color: #fff;
}
.qicon:hover {
  color: #fff;
}
/deep/ .ant-popover-arrow {
  display: none;
}
.qItem {
  width: 120px;
  text-align: left;
  padding-left: 20px;
  background-color: #f7f8fa;
  height: 38px;
  line-height: 35px;
  border: 1px solid #eee;
  border-radius: 3px;
  float: left;
  margin-bottom: 5%;
  &:hover {
    background-color: #e47c20;
    color: #fff;
    cursor: pointer;
  }
}
.qItem:nth-child(2n) {
  margin-left: 15px;
}
.cleanfix::after {
  clear: both;
  content: '';
  height: 0;
  display: block;
  overflow: visible;
}

.sider ul.ant-menu1 {
  padding: 15px !important;
  padding-top: 15px !important;
  padding-right: 15px !important;
  padding-bottom: 15px !important;
  padding-left: 15px !important;
}

/deep/ .ant-menu-dark,
.ant-menu-dark .ant-menu-sub {
  background-color: #0b5b31;
}
/deep/.ant-layout-sider-children {
  background-color: #0b5b31 !important;
}
/deep/.ant-menu-item {
  a {
    color: #fff !important;
  }
}
</style>